#include "DepthToRGBConverter.h"
#include <QDebug>
#include <memory>

DepthToRGBConverter::DepthToRGBConverter(cv::Mat lookUpTable) : Filter(1, 1), lookUpTable(lookUpTable)
{
	outputs[0] = cv::Mat(0, 0, CV_8UC3);
}


DepthToRGBConverter::~DepthToRGBConverter(void)
{
}

void DepthToRGBConverter::Process()
{
	if (outputs[0].size != inputs[0]->size)
	{
		outputs[0] = cv::Mat(inputs[0]->rows, inputs[0]->cols, CV_8UC3);
	}

	cv::Mat_<cv::Vec3b> output = outputs[0];
	cv::Mat_<ushort> input = *inputs[0];

	cv::Vec3b *lut = lookUpTable.ptr<cv::Vec3b>(0);

	for (int y = 0; y < output.rows; ++y)
	{
		cv::Vec3b *out = output.ptr<cv::Vec3b>(y);
		for (int x = 0; x < output.cols; ++x)
		{
			int index = ((ushort*)input.data)[y * input.cols + x];
			std::memcpy(out + x, lut + index, 3);
		}
	}
}
